//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Notification;
using OpenLS.Core.Serialization;
using OpenLS.Drawing;
using System.ComponentModel;

namespace OpenLS.Chart
{
    public class DataPoint : ViewModelBase, IOfficeXmlSerializable, IShape, IMarkerOwner
    {
        public DataPoint()
        {   
        }

        public DataPoint(int index)
        {
            Index = index;
        }
        private bool _bubble3D;
        private uint _explosion;
        private List<ExtensionElement> _extLst;
        private int _idx;

        private bool _invertIfNegative;

        private Marker _maker;
        private PictureOptions _pictureOptions;
        private ShapeProperties _spPr;

        public int Index
        {
            get { return _idx; }private set{ _idx = value;}
        }

        public bool InvertIfNegative
        {
            get { return _invertIfNegative; }
            set { _invertIfNegative = value; notifyPropertyChanged("InvertIfNegative");}
        }

        public Marker Marker
        {
            get { return _maker; }
            set { _maker = value; notifyPropertyChanged("Marker");}
        }

        public bool Bubble3D
        {
            get { return _bubble3D; }
            set { _bubble3D = value; notifyPropertyChanged("Bubble3D");}
        }

        public uint Explosion
        {
            get { return _explosion; }
            set { _explosion = value; notifyPropertyChanged("Explosion");}
        }

        public ShapeProperties ShapeProperties
        {
            get { return _spPr; }
            set { _spPr = value; notifyPropertyChanged("ShapeProperties");}
        }

        public PictureOptions PictureOptions
        {
            get { return _pictureOptions; }
            set { _pictureOptions = value; notifyPropertyChanged("PictureOptions");}
        }

        internal List<ExtensionElement> Extensions
        {
            get { return _extLst; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("dPt"))
            {
                _idx = c.ReadElementUIntegerAttributeAsInteger("idx", "val");
                _invertIfNegative = c.ReadOptionalElementBooleanAttribute("invertIfNegative", "val", false, true);
                Marker = c.ReadOptionalElement<Marker>("marker");
                Bubble3D = c.ReadOptionalElementBooleanAttribute("bubble3D", "val", false, true);
                _explosion = c.ReadOptionalElementUIntegerAttribute("explosion", "val", 0);
                ShapeProperties = c.ReadOptionalElement<ShapeProperties>("spPr");
                _pictureOptions = c.ReadOptionalElement<PictureOptions>("pictureOptions");
                _extLst = c.ReadOptionalListElement<ExtensionElement>("extLst", "ext");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("dPt"))
            {
                c.WriteElementUIntegerAttributeAsInteger("idx", "val", _idx);
                c.WriteOptionalElementBooleanAttribute("invertIfNegative", _invertIfNegative);
                c.WriteOptionalElement(Marker);
                c.WriteOptionalElementBooleanAttribute("bubble3D", Bubble3D);
                c.WriteOptionalElementUIntegerAttribute("explosion", "val", _explosion, 0);
                c.WriteOptionalElement(ShapeProperties);
                c.WriteOptionalElement(_pictureOptions);
                if (Extensions != null)
                    foreach (ExtensionElement e in Extensions)
                        c.WriteElement(e);
            }
        }

        #endregion

    }
}